#include "ftlineedit.h"
#include "ftcontrols.h"

FTLineEdit::FTLineEdit(const QString& t) :
    QLineEdit(t)
{
    _maxChars = -1;
}

void FTLineEdit::mouseReleaseEvent(QMouseEvent *)
{
    QEvent* event = new QEvent( QEvent::RequestSoftwareInputPanel );
    QCoreApplication::postEvent( this, event );
}

QSize FTLineEdit::sizeHint() const
{
    int min_height = FTControls::defaultHeight();
    QSize size = QLineEdit::sizeHint();
    if ( _maxChars > 0 )
    {
        QFontMetrics fm(font());
        QSize font_size = fm.size( Qt::TextSingleLine, "W" );
        size.setWidth(  font_size.width() * _maxChars );
    }
    if ( size.height() < min_height )
        size.setHeight( min_height );
    return size;
}

void FTLineEdit::setMaxChars(int mc)
{
    _maxChars = mc;
    setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed);
}
